<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class welcome_model extends CI_Model{
	
	
	
	function __construct(){
	 parent::__construct();
	
   }
   
   function insert($nd){	
    
	$query = $this->db->insert('information', $nd);
	//print_r($query);exit;
		if($this->db->affected_rows() > 0){
			return $query=$this->db->insert_id();
			
		}else{
			return 0;
		}	
		
   }
   
 function image_insert($arr){	
    
	$query = $this->db->insert('image', $arr);
	//print_r($query);exit;
		if($this->db->affected_rows() > 0){
			return $this->db->insert_id();
		}else{
			return 0;
		}	
		
   }
   
   function get_images($content_id){
   	 $sql="SELECT * FROM  image where content_id=$content_id";
  //echo $sql;
	 $query = $this->db->query ( $sql );
	 return $query->row_array();
	    	    	 
   }
   
   
   
 function list_images($content_id){
   	 $sql="SELECT * FROM  image where content_id=$content_id";
  //echo $sql;
	 $query = $this->db->query ( $sql );
	 return $query->result_array();
	    	    	 
   }
   
   
   /*
   function insert(){
   	$content = $_POST['content'];
   	$email = $_POST['email'];
   	$picture = $_POST['picture'];
   	$label = $_POST['label'];
    $add_time=date('Y-m-d H:i:s');
    $updata_time=date('Y-m-d H:i:s');
    $delete_time=date('Y-m-d H:i:s');   	
   	$sql = "INSERT INTO `message`.`information` (`content`,`email`,`picture`,`label`,`add_time`,`updata_time`,`delete_time`) values ('{$content}','{$email}','{$picture}','{$label}','{$add_time}','{$updata_time}','{$delete_time}')";
    print_r($sql);
   	$result = mysql_query($sql); 
   	return $result;  	   	   
   }  
   function detial($offset,$pagesize){
   	$sql = "select * from information order by id desc limit {$offset},{$pagesize}";
   //	print_r($sql);exit;
   	$query = mysql_query($sql);
   	
   	//$result = mysql_fetch_assoc($query);
   	//print_r($result);exit;
   	return $query;
   }
   function total(){
   	$sql = "select * from information";
   	$query = mysql_query($sql);
   	$result = mysql_num_rows($query);
   	//echo $result;
   	return $result;
   }*/  
   
   
   function detial( $offset='', $pagesize='') {
     	if(!is_numeric($offset)){	
     		$offset=0;
     	}
     	$offset=intval($offset);
		if ($pagesize > 0) {			
			$lmStr = "LIMIT $offset,$pagesize";
		} else {
			$lmStr = '';
		}
		$sql = "select * from information  ORDER BY updata_time desc $lmStr";
		//echo $sql;
		$query=$this->db->query ($sql);
		return $query->result_array ();
	}
   
   
   function total() {
		$sql = "select * from information";
		$query = $this->db->query ( $sql );
		$num = $query->num_rows ();
		return $num;
	}
	

   function get_detial($id){
   	    $sql="select * from information where id = $id";
   	    $query = $this->db->query ( $sql );
   	    return $query->row_array ();
   	
   }
   
   function del($text_id){
   	$sql="delete from information where id= $text_id";
   //	echo $sql;
    $query = $this->db->query ($sql);
   if($query->affected_rows()>0){
	    	return  true;
	    }else{
	    	return  false;
	    }
    
   }
   
   
   
   
   
   
}
	